package jzqb.dao.impl;

import cnki.tpi.kbatis.sqlsession.SqlSession;
import cnki.tpi.kbatis.utils.DataSourceUtil;
import jzqb.bo.NoticeBo;
import jzqb.dao.INoticeDao;
import jzqb.po.NoticePo;
import jzqb.vo.NoticeVo;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Description:
 *
 * @author BaiGe
 * @date: 2021/4/7 14:30
 * @Version 1.0
 */
@Repository
public class NoticeDaoImpl implements INoticeDao {

    @Override
    public List<NoticeVo> showNoticeList(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.showNoticeList";
        return sqlSession.selectList(statementId,noticeBo,false);
    }

    @Override
    public long showNoticeCount(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.showNoticeCount";
        return sqlSession.getCount(statementId,noticeBo);
    }

    @Override
    public Boolean insertNotice(NoticePo noticePo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.insertNotice";
        return sqlSession.executeInsert(statementId,noticePo);
    }

    @Override
    public Boolean delNotice(Integer id) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.delNotice";
        return sqlSession.executeDelete(statementId, id);
    }

    @Override
    public Boolean updateNotice(NoticePo noticePo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.updateNotice";
        return sqlSession.executeUpdate(statementId,noticePo);
    }

    @Override
    public List<NoticeVo> getNoticeSort() {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.getNoticeSort";
        return sqlSession.selectList(statementId,null,false);
    }

    @Override
    public Boolean serAllIsTopToNo() {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.serAllIsTopToNo";
        return sqlSession.executeUpdate(statementId,null);
    }

    @Override
    public List<NoticeVo> findBelongAndNotAllNoticeList(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findBelongAndNotAllNoticeList";
        return sqlSession.selectList(statementId,noticeBo,false);
    }

    @Override
    public long findBelongAndNotAllNoticeCount(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findBelongAndNotAllNoticeCount";
        return sqlSession.getCount(statementId,noticeBo);
    }

    @Override
    public NoticePo  findNoticeById(Integer noticeId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findNoticeById";
        return sqlSession.selectOne(statementId,noticeId,false);
    }

    @Override
    public Boolean updateReadUser(NoticePo noticePo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.updateReadUser";
        return sqlSession.executeUpdate(statementId, noticePo);
    }

    @Override
    public long getUnReadNoticeNum(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.getUnReadNoticeNum";
        return sqlSession.getCount(statementId, noticeBo);
    }

    @Override
    public List<NoticeVo> findSystemNoticeList(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findSystemNoticeList";
        return sqlSession.selectList(statementId,noticeBo,false);
    }

    @Override
    public long findSystemNoticeCount(NoticeBo noticeBo) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findSystemNoticeCount";
        return sqlSession.getCount(statementId,noticeBo);
    }

    @Override
    public List<NoticeVo> showSystemNoticeLimitFive() {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.showSystemNoticeLimitFive";
        return sqlSession.selectList(statementId,null,false);
    }

    @Override
    public NoticeVo findSystemNoticeById(Integer noticeId) {
        SqlSession sqlSession = DataSourceUtil.getSqlSession();
        String statementId = "jzqb.dao.INoticeDao.findSystemNoticeById";
        return sqlSession.selectOne(statementId,noticeId,false);
    }
}
